#define _CRT_SECURE_NO_WARNINGS 1
class Solution
{
public:
    void hanota(vector<int>& A, vector<int>& B, vector<int>& C)
    {
        dfs(A, B, C, A.size());
    }

    void dfs(vector<int>& A, vector<int>& B, vector<int>& C, int n)
    {
        if (n == 1)
        {
            C.push_back(A.back());
            A.pop_back();
            return;
        }
        dfs(A, C, B, n - 1);
        C.push_back(A.back());
        A.pop_back();
        dfs(B, A, C, n - 1);
    }
};

class Solution {
public:
    void reserve(vector<int>& nums, int left, int right)
    {
        while (left < right)
            swap(nums[left++], nums[right--]);
    }
    void rotate(vector<int>& nums, int k) {
        k %= nums.size();
        reserve(nums, 0, nums.size() - 1);
        reserve(nums, 0, k - 1);
        reserve(nums, k, nums.size() - 1);
    }
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* removeElements(ListNode* head, int val) {
        struct ListNode* phead = new ListNode(0, head);
        struct ListNode* tmp = phead;
        while (tmp->next)
        {
            if (tmp->next->val == val)
                tmp->next = tmp->next->next;
            else tmp = tmp->next;
        }
        return phead->next;
    }
};